//package com.example.caorl.job1to4.gateway.outbound.netty4;
//
//import com.example.caorl.job1to4.gateway.filter.HeaderHttpResponseFilter;
//import com.example.caorl.job1to4.gateway.filter.HttpResponseFilter;
//import io.netty.buffer.Unpooled;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//import io.netty.handler.codec.http.DefaultFullHttpResponse;
//import io.netty.handler.codec.http.FullHttpResponse;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.nio.charset.StandardCharsets;
//
//import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT;
//import static io.netty.handler.codec.http.HttpResponseStatus.OK;
//import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
//
//public class NettyHttpClientOutboundHandler  extends ChannelInboundHandlerAdapter {
//
//    HttpResponseFilter filter = new HeaderHttpResponseFilter();
//
//    private static Logger logger = LoggerFactory.getLogger(NettyHttpClientOutboundHandler.class);
//
//
//    @Override
//    public void channelActive(ChannelHandlerContext ctx)
//            throws Exception {
//
//
//    }
//
//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg)
//            throws Exception {
//        logger.info("msg is:{}", msg);
//        FullHttpResponse response = null;
//        try {
////            String value = "hello,kimmking";
////            response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(value.getBytes("UTF-8")));
////            response.headers().set("Content-Type", "application/json");
////            response.headers().setInt("Content-Length", response.content().readableBytes());
//
//
////            byte[] body = EntityUtils.toByteArray(endpointResponse.getEntity());
//            String body = "1111111";
////            System.out.println(new String(body));
////            System.out.println(body.length);
//
//            response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(body.getBytes(StandardCharsets.UTF_8)));
//
//            response.headers().set("Content-Type", "application/json");
//            response.headers().setInt("Content-Length", body.length());
//
//            filter.filter(response);
//
////            for (Header e : endpointResponse.getAllHeaders()) {
////                //response.headers().set(e.getName(),e.getValue());
////                System.out.println(e.getName() + " => " + e.getValue());
////            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//            response = new DefaultFullHttpResponse(HTTP_1_1, NO_CONTENT);
//            exceptionCaught(ctx, e);
//        } finally {
//            /*if (fullRequest != null) {
//                if (!HttpUtil.isKeepAlive(fullRequest)) {
//                    ctx.write(response).addListener(ChannelFutureListener.CLOSE);
//                } else {
//                    //response.headers().set(CONNECTION, KEEP_ALIVE);
//                    ctx.write(response);
//                }
//            }*/
//            ctx.write(response);
////            ctx.flush();
//            //ctx.close();
//        }
//    }
//}